package cn.huiyunche.base.service.interfaces.impl;

import cn.huiyunche.base.service.interfaces.IndexService;
import cn.huiyunche.base.service.mappers.SOrderMapper;
import cn.huiyunche.base.service.mappers.ext.SOrderViewMapper;
import cn.huiyunche.base.service.mappers.ext.SServiceOrderViewMapper;
import cn.huiyunche.base.service.model.SOrderExample;
import cn.huiyunche.base.service.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service
public class IndexServiceImpl implements IndexService {

    @Autowired
    private SOrderMapper sOrderMapper = null;

    @Autowired
    private SOrderViewMapper sOrderViewMapper = null;

    @Autowired
    private SServiceOrderViewMapper sServiceOrderViewMapper = null;

    private SServiceOrderViewMapper getSServiceOrderViewMapper() {
        return this.sServiceOrderViewMapper;
    }

    private SOrderViewMapper getSOrderViewMapper() {
        return this.sOrderViewMapper;
    }

    private SOrderMapper getSOrderMapper() {
        return this.sOrderMapper;
    }

    @Override
    public Map<String, Integer> selectCountAndAmount(String params) throws Exception {
        Map<String, Integer> map = new HashMap<String, Integer>();
        Date date = null;
        if ("day".equals(params)) {
            date = DateUtils.getCurrent00ZeroDate();
        } else if ("week".equals(params)) {
            date = DateUtils.getFirstDayOfWeek();
        } else if ("month".equals(params)) {
            date = DateUtils.getFirstDay0Month();
        }
        SOrderExample example = new SOrderExample();
        example.createCriteria().andCreateTimeGreaterThanOrEqualTo(date);
        map.put("countOrder", this.getSOrderMapper().countByExample(example));
        map.put("sumAmount", this.getSOrderViewMapper().sumAmount(date));
        return map;
    }

    @Override
    public Map<String, Integer> selectSchedule(String params) throws Exception {
        Map<String, Integer> map = new HashMap<String, Integer>();
        Date date = null;
        if ("day".equals(params)) {
            date = DateUtils.getCurrent00ZeroDate();
        } else if ("week".equals(params)) {
            date = DateUtils.getFirstDayOfWeek();
        } else if ("month".equals(params)) {
            date = DateUtils.getFirstDay0Month();
        }
        map.put("notSchedule", this.getSServiceOrderViewMapper().notSchedule(date));
        map.put("alreadySchedule", this.getSServiceOrderViewMapper().alreadySchedule(date));
        return map;
    }

}
